<template>
  <div class="box">
    <h1>B组件,{{ num }}</h1>
    <el-button type="primary" size="default" @click="handleAdd"
      >新增商品</el-button
    >

    <div v-for="item in filterGoods">
      名称：{{ item.name }} 价格:{{ item.price }}
    </div>
  </div>
</template>

<script>
export default {
  computed: {
    num() {
      return this.$store.state.count.num; //提取state数据
    },
    filterGoods() {
      return this.$store.getters["good/filterGoods"]; //提取getters数据
      // let obj = {
      // 'my-data':'数据包'
      // }
      // obj['my-data']
    },
  },
  methods: {
    handleAdd() {
      this.$store.commit("good/goodsAddMut", {
        name: "新商品",
        price: (Math.random() * 199 + 1).toFixed(2),
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.box {
  width: 50%;
  border: 1px solid #333;
  height: 500px;
}
</style>
